<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="#">通道管理</a></li>
		</ol>
	</section>
	<section class="content">
		<div class="work-list-switch">
			<a href="${ctx}/channel/list/assigned" <#if menu?? && menu=="assigned">class="current"</#if> >已分配</a>
			<a href="${ctx}/channel/list/unassigned" <#if menu?? && menu=="unassigned">class="current"</#if> >未分配</a>
		</div>
		<div class="box">
			<form action="${ctx}/channel/list/${menu}" method="get" id="listForm">
			<div class="box-header">
				<div class="row RowSearchWork">
					<div class="col-sm-12">
						<#if userType != 1>
						    <div class="col-sm-2 three-word">
								<label>代理商：</label> 
								<select class="form-control select2" name="agentId">
								   <option value="">请选择</option>
								   <#list agentList as a>
								        <#if agentId?exists && a.id == agentId>
											<option value="${a.id}" selected="selected">${a.nickName}</option>
										<#else>
										     <option value="${a.id}">${a.nickName}</option>
										</#if> 
								   </#list>
								</select>
							</div>
						    <#-- <div class="col-sm-2 three-word">
								<label>公司ID：</label> 
								<input type="text" class="form-control" name="companyId" value="${companyId!}" placeholder="请输入公司ID" />
							</div> -->
						</#if>
					    <div class="col-sm-2">
							<label>剩余：</label> 
							<select class="form-control" name="remain">
							   <option value="">请选择</option>
								<option value="3" <#if remain?exists && remain == 3>selected="selected"</#if> >3天内</option>
								<option value="5" <#if remain?exists && remain == 5>selected="selected"</#if> >5天内</option>
								<option value="7" <#if remain?exists && remain == 7>selected="selected"</#if> >7天内</option>
							</select>
						</div>
					    <div class="col-sm-2">
							<label>线路类型：</label> 
							<select class="form-control" name="channelType">
							   <option value="">请选择</option>
							   <#list channelTypeMap as key, value>
									<#if channelType?exists && key == channelType>
										<option value="${key}" selected="selected">${value}</option>
									<#else>
										<option value="${key}">${value}</option>
									</#if> 
							   </#list>
							</select>
						</div>
						<div class="col-sm-2">
							<label>状态：</label> 
							<select class="form-control" name="channelStatus">
							   <option value="">全部</option>
							   <#list channelStatusMap as key, value>
									<#if channelStatus?exists && key == channelStatus?string>
										<option value="${key}" selected="selected">${value}</option>
									<#else>
										<option value="${key}">${value}</option>
									</#if> 
							   </#list>
							</select>
						</div>
						<div class="col-sm-2 three-word width25">
							<label>关键字：</label>
							<#if menu?? && menu=="assigned">
								<input name="keyword" type="text" class="form-control" placeholder="请输入IP/TEL/企业名称" value="${keyword!}"/>
							</#if>
							<#if menu?? && menu=="unassigned">
								<input name="keyword" type="text" class="form-control" placeholder="请输入IP/TEL" value="${keyword!}"/>
							</#if>
						</div>
						<div class="col-sm-1">
							<input type="button" class="btn btn-default btn-search" onclick="channels.query()" value="查询" />
						</div>
					</div>
				</div>
			</div>
			<div class="box-body">
				<table class="table table-hover table-bordered table-striped table-hide">
					<thead>
						<tr>
							<th style="width:60px;">序号</th>
							<#-- <th>ID</th> -->
							<th>外呼号码</th>
							<th>IP/TEL</th>
							<#if menu?? && menu=="assigned">
								<th>企业名称</th>
							</#if>
							<th>线路类型</th>
							<th>AI数</th>
							<th>并发数</th>
							<th>计费</th>
							<th>开始日期</th>
							<th>到期日期</th>
							<th>剩余(天)</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<#list page.content as p>
						<tr>
							<td>${page.size * page.number + p_index+1}</td>
							<#-- <td>${p.channelId!}</td> -->
							<td>${p.channelName!}</td>
							<td>${p.channelNum!}</td>
							<#if menu?? && menu=="assigned">
								<th>${p.companyName!}</th>
							</#if>
							<td>
								<#if p.channelType?? && channelTypeMap["${p.channelType}"]?? >
									${channelTypeMap["${p.channelType}"]!}
								</#if>
							</td>
							<td><#if !p.robotNum?? || p.robotNum==0>1<#else>${p.robotNum!}</#if></td>
							<td>${p.concurrentNum!}</td>
							<td>
								<#if p.clearingForm?? && clearingFormMap["${p.clearingForm}"]?? >
									${clearingFormMap["${p.clearingForm}"]!}
								</#if>
							</td>
							<td><#if p.beginTime??>${p.beginTime?string("yyyy-MM-dd")}<#else></#if></td>
							<td><#if p.endTime??>${p.endTime?string("yyyy-MM-dd")}<#else></#if></td>
							<td>${p.remainDays!}</td>
							<td>
								<#if p.channelStatus?? && channelStatusMap["${p.channelStatus}"]?? >
									${channelStatusMap["${p.channelStatus}"]!}
								</#if>
							</td>
							<td>
								<#if userType = 1>
									<#if menu?? && menu=="unassigned">
										<a href="javascript:void(0)" onclick="channels.assign('${p.channelId}')" >分配</a>
									</#if>
									<#if p.channelType?? && p.channelType == 1>
										<a href="javascript:void(0)" onclick="channels.form('${p.channelId}')">编辑</a>
									<#else>
										<a href="javascript:void(0)" onclick="channels.pview('${p.channelId}')">查看</a>
									</#if>
								<#else>
									<#if p.channelType?? && p.channelType == 1>
										<a href="javascript:void(0)" onclick="channels.mview('${p.channelId}')">查看</a>
									<#else>
										<a href="javascript:void(0)" onclick="channels.pview('${p.channelId}')">查看</a>
									</#if>
								</#if>
							</td>
						</tr>
						</#list>
					</tbody>
				</table>
				<#include "../common/page.htm">
			</div>
			</form>
		</div>
	</section>
</div>

<script type="text/javascript">
	$('.select2').select2();
	$.fn.modal.Constructor.prototype.enforceFocus = function() {};

	var is_submit=false;
	var channels = {
		query : function() {
			$(":input[name='pageNumber']").val(0);
			$("form").submit();
		},
		assign : function(id) {
			base.getView({
				url : "${ctx}/channel/assign?channelId="+id,
				success : function(result) {
					bootbox.dialog({
						title : "通道分配",
						message : result,
						size : "large",
						buttons : {
							cancel : {
								label : "取消",
								className : "btn btn-secondary"
							},
							sure : {
								label : "确定",
								className : "btn btn-primary",
								callback : function() {
									base.validAndAjaxSubmit($("#assignChannel"), $("#listForm"));
									return false;
								}
							}
						}
					})
				}
			})
		},
		form : function(id){
			if(is_submit){
				return;
			}
			is_submit=true;
			var title = "编辑通道";
			var j = 0;
			base.getView({
				url:"${ctx}/channel/form?id="+id,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#editChannel"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
		mview : function(id){
			if(is_submit){
				return;
			}
			is_submit=true;
			var title = "查看SIM卡通道";
			base.getView({
				url:"${ctx}/channel/mview?id="+id,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							}
						}
					})
				}
			})
		},
		pview : function(id){
			if(is_submit){
				return;
			}
			is_submit=true;
			var title = "查看SIP线路通道";
			base.getView({
				url:"${ctx}/channel/pview?id="+id,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							}
						}
					})
				}
			})
		}
	}
</script>
<#include "../common/footer.htm">